#pragma once

#include "serverparticipant.h"
#include "GalconRoom.h"
#include <boost/asio.hpp>
#include <boost/enable_shared_from_this.hpp>
#include <deque>
#include "AbstractMessageFactory.h"

typedef std::deque<Message> MessageDeque;
using boost::asio::ip::tcp;

class GalconSession :
   public ServerParticipant, 
   public boost::enable_shared_from_this<GalconSession>
{
public:
   
   GalconSession(boost::asio::io_service& service, GalconRoom& room);
   
   ~GalconSession();
   
   tcp::socket& GetSocket()
   {
      return m_socket;
   }

   void Start();
   
   virtual void Deliver(const Message& msg);

private:

   void traceMessage(const Message&, const std::string&);

   void handle_read_header(const boost::system::error_code& error);

   void handle_read_body(const boost::system::error_code& error);

   void handle_write(const boost::system::error_code& error);

   GalconRoom& m_room;

   tcp::socket m_socket;

   Message m_message;

   MessageDeque m_messageDeque;

   AbstractMessageFactoryPtr m_messageFactory;
};

typedef boost::shared_ptr<GalconSession> GalconSessionPtr;